package com.bocai.dahuatech.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.NewProductBean;
import com.bocai.dahuatech.R;
import com.bocai.dahuatech.utils.SharePrefencesUtil;
import com.bumptech.glide.Glide;

public class HomeNewProductAdapter extends BaseAdapter {
    private Context context;
    NewProductBean datas;
    public HomeNewProductAdapter(Context context,NewProductBean datas){
        this.context=context;
        this.datas=datas;
    }
    @Override
    public int getCount() {
        return datas.getContent().size();
    }

    @Override
    public Object getItem(int position) {
        return datas.getContent().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null)
        {
            convertView= LayoutInflater.from(context).inflate(R.layout.home_newproduct_item,null);
            holder=new ViewHolder();
            holder.ivPic= (ImageView) convertView.findViewById(R.id.iv_newproduct_pic);
            holder.tvModel= (TextView) convertView.findViewById(R.id.tv_newproduct_model);
            holder.tvName= (TextView) convertView.findViewById(R.id.tv_newproduct_name);
            holder.tvPrice= (TextView) convertView.findViewById(R.id.tv_newproduct_price);
            convertView.setTag(holder);
        }else
        {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tvModel.setText(datas.getContent().get(position).getFOutModel());
        holder.tvName.setText(datas.getContent().get(position).getFItemName());
        if(SharePrefencesUtil.getFAccessFlag(context)==2){

            holder.tvPrice.setText(context.getResources().getString(R.string.money) +datas.getContent().get(position).getFStandPrice());
        }else{
            holder.tvPrice.setText("");

        }
        Glide.with(context).load(datas.getContent().get(position).getFImgSrc())
                .into(holder.ivPic);
        return convertView;
    }
    class ViewHolder{
        ImageView ivPic;
        TextView tvModel,tvName,tvPrice;
    }
}
